import java.util.Arrays;

class Solution {
    public int numSquares(int n) {
        int[] dp = new int[n + 1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;

        for (int i = 1; i * i <= n; i++) {
            int square = i * i;
            for (int j = square; j <= n; j++) {

                dp[j] = Math.min(dp[j], dp[j - square] + 1);

            }
        }

        return dp[n];
    }
}


class Solution1 {
    public int combinationSum4(int[] nums, int target) {
        int[] dp=new int[target+1];

        dp[0]=1;

        for(int j=1;j<=target;j++){
            for(int num:nums)
                if(j>=num)
                    dp[j]+=dp[j-num];
        }




        return dp[target];
    }
}


class Solution2 {
    public int findMaxForm(String[] strs, int m, int n) {
        int[][] dp=new int[m+1][n+1];

        //   dp[0][0]=1;

        for(String str:strs){
            int a=0;
            int b=0;
            char[] arr=str.toCharArray();
            for(char c:arr){
                if(c=='0') a++;
                else b++;
            }
            for(int i=m;i>=a;i--)
                for(int j=n;j>=b;j--){
                    dp[i][j]=Math.max(dp[i][j],dp[i-a][j-b]+1);

                }
        }

        return dp[m][n];
    }
}